# added by yinchao, Tue June 25 10:54	2024
# These is a link for 'Regular Expression How To', https://docs.python.org/3.6/howto/regex.html
# 需要理解 re.search 的返回值是什么类型

# the question mark indicates a none-greedy that tries to find the smallest possible matching string
# and a greedy match tries to find the longest possible matching string.
# what's none-greedy match in regular expressions ?

import re

s = 'yinchao y another yy'

if re.search('.+?', s):
    print(re.search('.+?', s).group())  # y, non-greedy model

r = re.findall('y.*?', s)
print(r)
print('===')
r = re.findall('y.*', s)
print(r)

print('-------------- findall over -----------------')

if re.search('.+', s):
    print(re.search('.+', s).group())  # yinchao greedy model


print('---------------------')
s = 'lsdkflsklk href="https://www.sphinx-doc.org/"lsdfldk sldkf href="https://www.python.org/psf/donations/" lsdlfk ldkkgl href="https://"'
r = re.findall('href="(http[s]?://.*?)"', s)
print(r)
r = re.findall('href="(http[s]?://.*)"', s)
print(r)
r = re.findall('href="(http[s]?://.*)', s)
print(r)
